<template>
  <div>
    <div class="provider-list">
      <div class="header">
        <div class="header-line2 flex-s">
          <el-input
            v-model="params.neirong"
            placeholder="请输入内容"
            style="width: 350px"
            size="large"
          >
            <template #append>
              <el-button
                @click="GetList"
                style="min-width: 50px"
                icon="Search"
              />
            </template>
          </el-input>
          <el-col :span="8">
            <el-date-picker
              v-model="chooseTime"
              type="daterange"
              range-separator="To"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              size="large"
              class="ml20"
              prefix-icon="Calendar"
              value-format="YYYY-MM-DD"
              @change="changeTime"
            />
          </el-col>
        </div>
      </div>
      <div class="content content-table">
        <el-table
          ref="multipleTableRef"
          border
          :data="list"
          style="width: calc(100% - 20px)"
        >
          <el-table-column
            property="id"
            label="ID"
            width="100"
            align="center"
          />
          <el-table-column property="nicheng" label="用户昵称" align="center" />
          <el-table-column
            property="lianxifangshi"
            label="账号"
            width="130"
            align="center"
          />
          <el-table-column
            property="shenqingriqi"
            label="申请时间"
            width="300"
            align="center"
          />
          <el-table-column
            property="xingming"
            label="姓名"
            width="150"
            align="center"
          />
          <el-table-column
            property="lianxifangshi"
            label="联系方式"
            width="200"
            align="center"
          />
          <el-table-column label="是否办理" align="center">
            <template #default="scope">
              <span v-if="scope.row.banli && scope.row.banli.code">{{
                scope.row.banli.code == 0 ? "未办理" : "已办理"
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="有效期" width="200" align="center">
            <template #default="scope">
              <span v-if="scope.row.goumairiqi && scope.row.jiezhiriqi">
                {{ scope.row.goumairiqi + '-——' + scope.row.jiezhiriqi }}
              </span>
            </template>
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="80" align="center">
            <template #default="scope">
              <el-button
                style="min-width: auto"
                link
                type="primary"
                size="small"
                @click.prevent="onOperation(scope.row, 'detail')"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <h-page
          v-if="total"
          v-model:curr-page="params.current"
          :size="params.size"
          :total="total"
          @change="GetList"
        />
      </div>
    </div>
  </div>
</template>
<script>
import { defineComponent, toRefs, reactive, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { GetMemberOrderList } from "@/api/membership";
export default defineComponent({
  setup() {
    const route = useRoute();
    const router = useRouter();
    const state = reactive({
      params: {
        current: Number(route.query.page) || 1,
        size: Number(route.query.size) || 10,
        neirong: "",
        huiyuanleixing: "qiyehuiyuan",
        kaishiriqi: "",
        jieshuriqi: "",
      },
      list: [],
      // 时间选择器时间
      chooseTime: [],
      total: 0,
    });

    const GetList = async () => {
      const res = await GetMemberOrderList(state.params);
      state.list = res.data.records;
      state.total = res.data.total;
    };
    // 时间选择
    const changeTime = (value) => {
      if (value) {
        state.params.kaishiriqi = value[0];
        state.params.jieshuriqi = value[1];
      } else {
        state.params.kaishiriqi = "";
        state.params.jieshuriqi = "";
      }
      GetList();
    };
    // 操作
    const onOperation = (params, operation) => {
      if (operation === "detail") {
        router.push({
          path: `/huiyuanquanyi/detail`,
          query: {
            id: params.id,
          },
        });
      }
    };
    watch(
      () => route.query,
      () => {
        state.params.current = Number(route.query.page) || 1;
        GetList();
      },
      { deep: true }
    );
    GetList();
    return {
      ...toRefs(state),
      GetList,
      onOperation,
      changeTime,
    };
  },
});
</script>
<style lang="scss" scoped>
.header {
  border-bottom: 10px solid #f2f2f2;
  border-radius: 10px 10px 0 0;
}
.header-line1 {
  padding: 20px 10px;
  border-bottom: 1px solid #ccc;
  border-radius: 10px 10px 0 0;
}
.header-line2 {
  padding: 20px 10px;
}
.content {
  border: none !important;
  margin: 20px 10px;
  background-color: transparent !important;
}
</style>
<style lang="scss">
.content-table .el-table__header th {
  background-color: #f2f9fc !important;
}
</style>
